import Vue from 'vue'

import API from '../config/musicApi'

function apiFactory(api) {
  return ( id = null ) => Vue.http.jsonp(
    api.url,
    {
      params: api.params(id),
      jsonp: api.jsonp
    }
  )
}

export default {
  actions: {
    getRankList({}) {
      return apiFactory( API.rank_list )()
    },
    getRankSongs({}, id) {
      return apiFactory( API.rank_songs )(id)
    },
    getHotkey({}) {
      return apiFactory( API.hotkey )()
    },
    search({}, key) {
      return apiFactory( API.search )(key)
    },
    getAlbum({}, id) {
      return apiFactory( API.album )(id)
    },
    getSingerInfo({}, id) {
      return apiFactory( API.singer_info )(id)
    },
    getLyric({}, id) {
      return Vue.http.jsonp(`https://api.darlin.me/music/lyric/${id}+/`, {
        jsonp: 'callback'
      })
    }
  }
}